import lxml.etree as le

with open('index.htm','r',encoding='utf-8') as f:
    html=f.read()   # 读取文本
    html_x=le.HTML(html)  # 转换成xpath可处理文本
    div_x_s=html_x.xpath('//div[@class="classify_c"]/div')   # 获取一级标题 二级标题

    data_s = []   # 定义列表保存最终取得的一级二级标题文本
    for div_x in div_x_s:   # 遍历每个[一级标题+其下属的二级标题]
        category1 = div_x.xpath('./h3/a/text()')[0]  # 获取一级标题
        category2_s = div_x.xpath('./div/span/a/text()')  # 获取二级标题
        data_s.append(
            dict(
                category1=category1,   # 保存一级标题
                category2_s=category2_s   # 保存二级标题
            )
        )

    for data in data_s:  # 遍历获取的数据列表
        print(data.get('category1'))  # 打印一级标题
        for category2 in data.get('category2_s'):  # 打印一级标题下属的二级标题
            print('   ',category2)
